<?php
session_start();
/**
Eventos de FrmTableUsers
**/
//Variables de session
$_SESSION['tableUsersIdOrder'];//0 Asc 1 Desc
$_SESSION['tableUsersNombreOrder'];
$_SESSION['tableUsersApellidoOrder'];
$_SESSION['tableUsersNickOrder'];
//-------------------

//MApache
require '../../../MApache/weblinx/weblinx.php';
//-------

//----Formularios requeridos----

//------------------------------

//----Clases requeridas---------
require("../Classes/Setter.php");
require("../Classes/Sentinel.php");
require("../Classes/User.php");
require("../Forms/FrmTableUsers.php");
require("../Forms/FrmUserEdit.php");
require("../Forms/FrmUserInfo.php");
//-----------------------------

//---Events--------------------

if(isset($_POST['editar'])){
	$user=new User();
	$user->cargar($_POST['editar']);
	
	$frmUserEdit=new FrmUserEdit($user);
	$frmUserEdit->show();
}
else if(isset($_POST['eliminar'])){
	$messageBox=new MessageBox($image="../../../MApache/weblinx/Images/danger.png",$messageText="<b>¿Segur@ que quiere eliminar a este usuario? <br /> Cedula: ".$_POST['eliminar']." </b>",$okButtonName="okValidatorFrmUserEliminar",$okButtonValue="ok",$okButtonEvents=array("onclick"=>"GETMethodSend('cedulaE','okValidatorFrmUserEliminar','tableUsers','../Events/EventsFrmTableUsers.php')"),$cancelButtonName="cancelValidatorFrmUserEliminar",$cancelButtonValue="cancel",$cancelButtonEvents=array("onclick"=>"GETMethodSend('cancelValidatorFrmUserEliminar','tableUsers','../Events/EventsFrmTableUsers.php')"));
	$messageBox->addHiddenData("cedulaE",$_POST['eliminar']);
	$messageBox->setVisible("visible");
	$messageBox->show();	
}
else if(isset($_GET['okValidatorFrmUserEliminar'])){
	$user=new User();
	$user->cargar($_GET['cedulaE']);
	$user->eliminar();
	
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->show();
}
else if(isset($_GET['cancelValidatorFrmUserEliminar'])){
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->show();
}

else if(isset($_POST['masInfo'])){
	$user=new User();
	$user->cargar($_POST['masInfo']);
	
	$frmUserInfo=new FrmUserInfo($user);
	$frmUserInfo->show();
}

//Ordenamiento por los titulos de la tabla
else if(isset($_POST['id'])){
	if($_SESSION['tableUsersIdOrder']==0){
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY id ASC";
		$_SESSION['tableUsersIdOrder']=1;
	}
	else{
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY id DESC";
		$_SESSION['tableUsersIdOrder']=0;
	}
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}

else if(isset($_POST['Nombre'])){
	if($_SESSION['tableUsersNombreOrder']==0){
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY nombre ASC";
		$_SESSION['tableUsersNombreOrder']=1;
	}
	else{
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY nombre DESC";
		$_SESSION['tableUsersNombreOrder']=0;
	}
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}

else if(isset($_POST['Apellido'])){
	if($_SESSION['tableUsersApellidoOrder']==0){
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY apellido ASC";
		$_SESSION['tableUsersApellidoOrder']=1;
	}
	else{
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY apellido DESC";
		$_SESSION['tableUsersApellidoOrder']=0;
	}
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}

else if(isset($_POST['Nick'])){
	if($_SESSION['tableUsersNickOrder']==0){
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY nick ASC";
		$_SESSION['tableUsersNickOrder']=1;
	}
	else{
		$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios ORDER BY nick DESC";
		$_SESSION['tableUsersNickOrder']=0;
	}
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}
else if(isset($_POST['Telefono'])){
	$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios";
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}
else if(isset($_POST['Direccion'])){
	$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios";
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}
else if(isset($_POST['Email'])){
	$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios";
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}
else if(isset($_POST['Rol'])){
	$consult="SELECT id, nombre, apellido, nick, telefono, direccion, email, idRol FROM usuarios";
	$frmTableUsers=new FrmTableUsers();
	$frmTableUsers->setDbConsult($consult);
	$frmTableUsers->show();
}
//----------------------------------------

?>